﻿function showLoader() {
    document.getElementById('loader').style.display = "inline-block";
}



var curTime = new Date();
var curYear = curTime.getFullYear();
var curMonth = curTime.getMonth() + 1;
var curDay = curTime.getDate();

function setDays() {
    var day = document.getElementById('day');
    var month = document.getElementById('month');
    var year = document.getElementById('year');

    var selectedMonth = month.selectedIndex - 1;
    var selectedYear = parseInt(year.options[year.selectedIndex].text);
    var selectedDayIndex = day.selectedIndex;

    var limit = 31;
    if ((selectedYear == curYear) && (selectedMonth == curMonth)) {
        limit = curDay;
    }
    if (selectedMonth == 4 || selectedMonth == 6 || selectedMonth == 9 || selectedMonth == 11) {
        limit = 30;
    }
    if (selectedMonth == 2) {
        limit = getFebDays();
    }
    day.length = limit + 1;

    var str = new String();
    var k = 1;
    for (var i = 1; i <= limit; i++) {
        if (i < 10) {
            str = "0" + i;
        }
        else {
            str = i;
        }
        day.options[k] = new Option(str, str);
        k++;
    }

    if (selectedDayIndex < day.length) {
        day.selectedIndex = selectedDayIndex;
    }
    else {
        day.selectedIndex = 0;
    }
}



function setMonths() {
    var month = document.getElementById('month');
    var year = document.getElementById('year');
    var selectedYear = parseInt(year.options[year.selectedIndex].text);
    var selectedMonthIndex = month.selectedIndex;
    var limit = 12;

    if (selectedYear == curYear) {
        limit = curMonth;
    }
    month.length = limit + 1;

    var str = new String();
    var k = 1;
    for (var i = 1; i <= limit; i++) {
        if (i < 10) {
            str = "0" + i;
        }
        else {
            str = "" + i;
        }
        month.options[k] = new Option(str, str);
        k++;
    }

    if (selectedMonthIndex < month.length) {
        month.selectedIndex = selectedMonthIndex;
    }
    else {
        month.selectedIndex = 0;
    }
}



function setYears() {
    var year = document.getElementById('year');
    var k = 1;
    for (var i = curYear - 18; i >= 1920; i--) {
        year.options[k] = new Option(i, i);
        k++;
    }
}



function getFebDays() {
    var year = document.getElementById('year');
    var year = parseInt(year.options[year.selectedIndex].text);
    if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
        return 29;
    }
    return 28;
}